home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / pack / xpk_Source.lha / xpk_Source / test / testXpkMasterPrefsSem.c < prev    next >
C/C++ Source or Header  |  1998-11-09  |  4KB  |  139 lines

  1. #define NAME        "testXpkMasterPrefsSem"
  2. #define DISTRIBUTION    "(Freeware) "
  3. #define REVISION    "6"
  4.  
  5. /* NOTE: This program depends on certain things, which may change. It is
  6. only valid as long as the XpkMasterPrefs internal structures do not change.
  7. It is only for tests and no standard use tool!!! Never distribute a binary
  8. version of it or use it's routines in other programs! */
  9.  
  10. /* Programmheader
  11.  
  12.     Name:        testXpkMasterPrefsSem
  13.     Author:        SDI
  14.     Distribution:    Freeware
  15.     Description:    tests "« XpkMasterPrefs »" Semaphore work
  16.     Compileropts:    -
  17.     Linkeropts:    -
  18.  
  19.  1.0   25.12.96 : first Version
  20.  1.1   26.12.96 : xpkprefs.h changed nearly totally
  21.  1.2   27.12.96 : reduced length of Forbid()/Permit()
  22.  1.3   28.02.97 : semaphore style changed
  23.  1.4   01.03.97 : XpkMainPrefs changed a bit
  24.  1.5   24.03.97 : error fix
  25.  1.6   02.04.97 : changed the XpkTypeData structure
  26. */
  27.  
  28. #include <proto/exec.h>
  29. #include <proto/dos.h>
  30. #include <exec/memory.h>
  31. #include "SDI_defines.h"
  32. #include "PrintFlags.c"
  33. #include <xpk/xpkprefs.h>
  34.  
  35. /* This is a XpkMasterPrefs private structure !!!!! */
  36.  
  37. struct XpkTypeNode {
  38.   struct Node        xtn_Node;
  39.   ULONG            xtn_Size;
  40.   struct XpkTypePrefs    xtn_TypePrefs;
  41. };
  42.  
  43. void WriteXpkTypeData(struct XpkTypeData *xp)
  44. {
  45.   STRPTR a = 0;
  46.  
  47.   PutStr("xtd_Flags     : ");
  48.   {
  49.     ULONG i = xp->xtd_Flags;
  50.     PrintFlag(&i, XTD_NoPack,      "XTD_NoPack");
  51.     PrintFlag(&i, XTD_ReturnError, "XTD_ReturnError");
  52.     PrintEndFlag(i, xp->xtd_Flags);
  53.   }
  54.   a = (STRPTR) &xp->xtd_StdID;
  55.   VPrintf("xtd_StdID     : %lx", a);
  56.   VPrintf(" (%.4s)\n", &a);
  57.   VPrintf(
  58.   "xtd_ChunkSize : %ld\n"
  59.   "xtd_Mode      : %d\n"
  60.   "xtd_Version   : %d\n"
  61.   "xtd_Password  : %s\n", &xp->xtd_ChunkSize);
  62. }
  63.  
  64. void WriteXpkTypePrefs(struct XpkTypePrefs *xp)
  65. {
  66.   PutStr("xtp_Flags       : ");
  67.   {
  68.     ULONG i = xp->xtp_Flags;
  69.     PrintFlag(&i, XPKT_NamePattern, "XPKT_NamePattern");
  70.     PrintFlag(&i, XPKT_FilePattern, "XPKT_FilePattern");
  71.     PrintEndFlag(i, xp->xtp_Flags);
  72.   }
  73.   VPrintf(
  74.     "xtp_TypeName    : %s\n"
  75.     "xtp_NamePattern : %s\n"
  76.     "xtp_FilePattern : %s\n"
  77.     "xtp_PackerData  :\n", &xp->xtp_TypeName);
  78.   WriteXpkTypeData(xp->xtp_PackerData);
  79. }
  80.  
  81. void WriteXpkMainPrefs(struct XpkMainPrefs *xp)
  82. {
  83.   VPrintf("xmp_Version     : %ld\n", &xp->xmp_Version);
  84.   PutStr("xmp_Flags       : ");
  85.   {
  86.     ULONG i = xp->xmp_Flags;
  87.     PrintFlag(&i, XPKM_UseXFD, "XPKM_UseXFD");
  88.     PrintFlag(&i, XPKM_AutoPassword, "XPKM_AutoPassword");
  89.     PrintFlag(&i, XPKM_UseExternals, "XPKM_UseExternals");
  90.     PrintEndFlag(i, xp->xmp_Flags);
  91.   }
  92.   PutStr("xmp_DefaultType :\n");
  93.   WriteXpkTypeData(xp->xmp_DefaultType);
  94.   VPrintf("xmp_Timeout     : %d\n", &xp->xmp_Timeout);
  95. }
  96.  
  97. ULONG main(void)
  98. {
  99.   struct XpkPrefsSemaphore *sem;
  100.  
  101.   Forbid();
  102.   if((sem = (struct XpkPrefsSemaphore *) FindSemaphore(XPKPREFSSEMNAME)))
  103.     ObtainSemaphoreShared((struct SignalSemaphore *) sem);
  104.   Permit();
  105.  
  106.   if(sem)
  107.   {
  108.     VPrintf("xps_Version       : %ld\n", &sem->xps_Version);
  109.     {
  110.       STRPTR b;
  111.       b = (STRPTR) &sem->xps_PrefsType;
  112.       VPrintf("xps_PrefsType     : %lx", b);
  113.       VPrintf(" (%.4s)\n", &b);
  114.     }
  115.     VPrintf("xps_RecogSize     : %ld\n", &sem->xps_RecogSize);
  116.  
  117.     if(sem->xps_MainPrefs)
  118.     {
  119.       WriteXpkMainPrefs(sem->xps_MainPrefs);
  120.       PutStr("\n");
  121.     }
  122.  
  123.     if(sem->xps_PrefsType == XPREFSTYPE_STANDARD)
  124.     {
  125.       struct Node *n;
  126.       n = ((struct List *) sem->xps_PrefsData)->lh_Head;
  127.  
  128.       for(;n->ln_Succ && !CTRL_C; n = n->ln_Succ)
  129.       {
  130.         WriteXpkTypePrefs(&((struct XpkTypeNode *) n)->xtn_TypePrefs);
  131.         PutStr("\n");
  132.       }
  133.     }
  134.     ReleaseSemaphore((struct SignalSemaphore *) sem);
  135.   }
  136.   else
  137.     PutStr(XPKPREFSSEMNAME " Semaphore not found.\n");
  138. }
  139.